$(() => {obj.init()});

let obj = {
    dataGrid: null,
    dom: {
        startTime: null,
        endTime: null,
        province: null,
        city: null,
        county: null
    },
    init: function () {
        this.dom.startTime = $('#list_startTime');
        this.dom.endTime = $('#list_endTime');
        this.dom.province = $('#list_province');
        this.dom.city = $('#list_city');
        this.dom.county = $('#list_county');


        this.dataGrid = new xhDataGrid($('#list'), 'statsschool/risingData');
        this.dataGrid.parseToolbar();//.init();//.activeBtn($('#bt_list_del'), $('#bt_list_add'));

        this.dom.startTime.datebox('setValue', (new Date()).getFullYear() - 1 + '-01-01');
        this.dom.endTime.datebox('setValue', (new Date()).getFullYear() - 1 + '-12-31');

        this.listener();
    },
    listener: function () {
        //查找
        $('#bt_list_search').click(() => {
            this.funObj().search(); 
        }).click();
        //省筛选
        this.funObj().initArea();
    },
    funObj: function(){
        return {
            search: () => {
                this.dataGrid.reload({
                    status: xhExtra.getValue($('#list_status')),
                    startTime: xhExtra.getValue($('#list_startTime')),
                    endTime: xhExtra.getValue($('#list_endTime')),
                    province: this.dom.province.combobox('getText'),
                    city: this.dom.city.combobox('getText'),
                    county: this.dom.county.combobox('getText'),
                })
            },
            initArea: () => {
                this.dom.city.combobox({
                    valueField: 'code',
                    textField: 'name',
                    data: [
                        {code: '', name: '--市--'}
                    ]
                });
                this.dom.county.combobox({
                    valueField: 'code',
                    textField: 'name',
                    data: [
                        {code: '', name: '--区--'}
                    ]
                });
                this.dom.province.combobox({
                    url: '/other/getChildArea/?empty=true',
                    valueField: 'code',
                    textField: 'name',
                    panelHeight: 300,
                    onSelect: (province) => {
                        if (province.code) {
                            this.dom.city.combobox({
                                url: '/other/getChildArea/' + province.code + '?empty=true',
                                valueField: 'code',
                                textField: 'name',
                                onSelect: (city) => {
                                    if (city.code) {
                                        this.dom.county.combobox({
                                            url: '/other/getChildArea/' + city.code + '?empty=true',
                                            valueField: 'code',
                                            textField: 'name'
                                        });
                                    } else {
                                        this.dom.county.combobox('loadData', [{code: '', name: '--区--'}]).combobox('setValue', '');
                                    }
                                }
                            });
                        } else {
                            this.dom.city.combobox('loadData', [{code: '', name: '--市--'}]).combobox('setValue', '');
                            this.dom.county.combobox('loadData', [{code: '', name: '--区--'}]).combobox('setValue', '');
                        }
                    }
                });
            }
        }
    }
};